<template>
  <view>
    <u-navbar title="订单详情" :border-bottom="false" back-icon-size="48"></u-navbar>
    <view class="banner">
      <view class="status" v-if="isOK">
        {{ {0:'待确认',1:'已取消',2:'已完成',3:'用户删除'}[items.order_status] }}
      </view>
      <view class="status" v-else>
        <view>{{ {0:'待确认',1:'已取消',2:'已完成',3:'用户删除'}[items.order_status] }}</view>
        <view style="font-size: 28rpx;">30分钟内未付款订单将自动取消</view>
      </view>
    </view>
    <view class="main">
      <view class="address">
        <view class="top">
          <image class="icon" src="../../../../static/imgs/map.png" mode=""></image>
          <view class="name">
            {{ items.name }}
          </view>
          <view class="mobile">
            {{ items.mobile }}
          </view>
        </view>
        <view class="bot">
          {{ items.address }}
        </view>
      </view>
      <view class="product">
        <view class="top">
          <text>爱世界超值商城</text>
          <text style="color: #FF4600;">{{ items.finish_time.order_status_name }}</text>
        </view>
        <view class="mid">
          <image class="shopimg" :src="items.goodsSku[0].image_path" mode=""></image>
          <view class="tit">
            厚切芒果干100g*3袋水果干蜜饯果
            厚切芒果干100g*3袋水果干蜜饯果
          </view>
          <view class="num">
            x{{ items.goodsSku[0].num }}
          </view>
        </view>
        <view class="price">
          <view class="price-sf">
            实付款<text>¥ {{ items.order_amount }}</text>
          </view>
          <view class="price-yh">
            优惠<text>¥ {{ items.welfare_fund }}</text>
          </view>
          <view class="price-zj">
            总价<text>¥ {{ items.order_price }}</text>
          </view>
        </view>
      </view>
      <view class="orderInfo" v-if="items.order_status !== '1'">
        <view class="order-li">
          <view class="lable">
            订单编号：
          </view>
          <view class="num">
            {{ items.order_sn }}
          </view>
          <view class="copy" @click="copy">
            复制订单
          </view>
        </view>
        <view class="order-li">
          <view class="lable">
            创建时间：
          </view>
          <view class="num">
            {{ items.create_time }}
          </view>
        </view>
        <view class="order-li">
          <view class="lable">
            付款时间：
          </view>
          <view class="num">
            2020/11/01 10:25
          </view>
        </view>
        <view class="order-li">
          <view class="lable">
            发货时间：
          </view>
          <view class="num">
            2020/11/01 10:25
          </view>
        </view>
      </view>
      <view class="btn" @click="delOrder" v-if="items.order_status !== '1'">
        删除订单
      </view>
      <view class="btns" v-else>
        <view class="btnitem" @click="navTo('./editaddress?order_id='+items.id+'&name='+items.name+'&mobile='+items.mobile+'&address='+items.address)">
          修改地址
        </view>
        <view class="btnitem">
          取消订单
        </view>
        <view class="btnitemPay">
          去支付
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import oRequest from '@/api/order'
export default {
  data() {
    return {
      isOK : false,
      id   : 0,
      items: {}
    }
  },
  onLoad(options) {
    this.id = options.id
    this.getOrderDetails()
  },
  methods: {
    init() {
    },
    async getOrderDetails() {
      const id = this.id
      let res = await oRequest.getShopOrderDetails({order_id:id})
      if(res.status){
        this.items = res.data
      }
      console.log(res)
    },
    copy(){
      const data = this.items.order_sn
      uni.setClipboardData({
                             data:data,
                             success:function(){
                               uni.showToast({
                                               title: '复制成功',
                                               duration: 2000,
                                               icon: 'none'
                                             });
                             },
                             fail:function(err){
                               uni.showToast({
                                               title: '复制失败',
                                               duration: 2000,
                                               icon: 'none'
                                             });
                             }

                           })
    },
    delOrder(){
      const _this = this
      uni.showModal({
        title:'订单删除',
        content:'订单删除后将不可恢复，确定删除吗？',
        confirmColor:'#FF4141',
        success:function(res){
          if(res.confirm){
            _this.doDeleteOrder()
          }
        }
                    })
    },
    async doDeleteOrder(){
      let id = this.id
      let res = await oRequest.delShopOrder({order_id:id})
      if(res.status){
        uni.showToast({
                        title:'删除成功',
                        icon:'none'
                      })
        setTimeout(()=>{
          uni.navigateTo({
                           url:'./store'
                         })
        },2000)
      }
    },
    //修改地址
    async updateAddress(){

    },
    async cancelOrder(){
      let id = this.id
      let res = await oRequest.cancelShopOrder({order_id:id})
      if(res.status){
        uni.showToast({
          title:res.msg,
          icon:'none'
                      })
      }
    },
    navTo(url){
      uni.navigateTo({
                       url:url
                     })
    }
  }
}
</script>
<style lang="scss" scoped>
.banner {
  width: 100%;
  height: 280rpx;
  @include bgi('../../../../static/imgs/ddxqbgi.png');
  padding-top: 60rpx;
  padding-left: 48rpx;

  .status {
    font-size: 36rpx;
    font-family: Segoe UI;
    font-weight: 400;
    color: #FFF;
  }
}

.main {
  padding: 0 28rpx;
  margin-top: -108rpx;

  .address {
    width: 100%;
    height: 176rpx;
    background: #FFF;
    border-radius: 16rpx;

    .top {
      display: flex;
      align-items: center;
      padding-top: 32rpx;
      padding-left: 20rpx;

      .icon {
        width: 48rpx;
        height: 48rpx;
      }

      .name {
        font-size: 36rpx;
        font-family: PingFangSC-Regular;
        color: #120404;
        font-weight: bold;
        margin-left: 20rpx;
      }

      .mobile {
        font-size: 28rpx;
        font-family: PingFangSC-Light;
        font-weight: 400;
        color: #666;
        margin-left: 20rpx;
      }
    }

    .bot {
      margin-top: 6rpx;
      padding-left: 88rpx;
      padding-right: 88rpx;
      font-size: 24rpx;
      font-family: PingFangSC-Light;
      color: #999;
    }
  }

  .product {
    width: 100%;
    height: 344rpx;
    background: #FFF;
    border-radius: 16rpx;
    margin-top: 32rpx;

    .top {
      height: 88rpx;
      padding: 0 20rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 28rpx;
      font-family: Arial;
      font-weight: 400;
      color: #333;
    }

    .mid {
      display: flex;
      padding: 0 20rpx;

      .shopimg {
        width: 160rpx;
        height: 160rpx;
      }

      .tit {
        margin-left: 24rpx;
        width: 60%;
        font-size: 30rpx;
        font-family: Segoe UI;
        font-weight: 400;
        color: #333;
      }

      .num {
        margin-left: auto;
        font-size: 28rpx;
        font-family: Segoe UI;
        font-weight: 400;
        color: #333;
      }
    }

    .price {
      font-size: 24rpx;
      font-family: Segoe UI;
      font-weight: 400;
      color: #666;
      padding: 22rpx 20rpx 22rpx 0;
      text-align: right;
      justify-content:flex-end;
      align-items:center;
      view{
        padding: 22rpx 20rpx 22rpx 0;
        text-align: right;
        float:right;
      }
      .price-sf{}
      .price-zj{
        text{
          color: #666666;
        }
      }
      .price-yh{
        color: #FF4600;
        text{
          color: #FF4600;
        }
      }
      view>text {
        font-size: 32rpx;
        font-family: Segoe UI;
        font-weight: 400;
        color: #333333;
        margin-left: 6rpx;
      }
    }
  }

  .orderInfo {
    margin-top: 32rpx;
    width: 694rpx;
    height: 266rpx;
    background: #FFF;
    border-radius: 16rpx;
    padding: 10rpx 20rpx;
    display: flex;
    flex-direction: column;

    .order-li {
      flex: 1;
      display: flex;
      align-items: center;

      .lable {
        font-size: 28rpx;
        font-family: PingFangSC-Light;
        color: #999;
      }

      .num {
        font-size: 28rpx;
        font-family: PingFangSC-Light;
        color: #120404;
      }

      .copy {
        margin-left: auto;
        width: 112rpx;
        height: 40rpx;
        border: 2rpx solid #2D7AFE;
        border-radius: 8rpx;
        font-size: 24rpx;
        font-family: Arial;
        font-weight: 400;
        color: #2D7AFE;
        text-align: center;
        line-height: 40rpx;
      }
    }
  }

  .btn {
    margin-top: 32rpx;
    width: 694rpx;
    height: 100rpx;
    background: #FFF;
    border-radius: 16rpx;
    text-align: center;
    font-size: 28rpx;
    font-family: Segoe UI;
    font-weight: 400;
    line-height: 100rpx;
    color: #333333;
  }

  .btns {
    margin-top: 32rpx;
    width: 694rpx;
    height: 100rpx;
    background: #FFF;
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: space-around;

    .btnitemPay {
      width: 176rpx;
      height: 60rpx;
      border: 1px solid #FF7C0A;
      color: #FF7C0A;
      border-radius: 40rpx;
      text-align: center;
      line-height: 60rpx;
    }
  }
}
</style>
